package com.pagoda.nerp.trade.common.objectutil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Created by Jungle on 2016/12/19.
 */
public class CustomizedPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

    private static final Logger logger = LoggerFactory.getLogger(CustomizedPropertyPlaceholderConfigurer.class);
    private static Map ctxPropertiesMap;

    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
                                    Properties props)throws BeansException {
        super.processProperties(beanFactoryToProcess, props);
        ctxPropertiesMap =new HashMap();
        for(Object key : props.keySet()) {
            String keyStr = key.toString();
            String value = props.getProperty(keyStr);
            ctxPropertiesMap.put(keyStr, value);
        }
        logger.debug("================+++++++ 属性文件初始化完成 ++++++++=====================");
        logger.debug("配置参数:{}",ctxPropertiesMap);
    }

    public static Object getContextProperty(String name) {
        return ctxPropertiesMap.get(name);
    }
}
